/*
直接更新 state 的多个方法的对象
*/
import oilGeo_point from "@/components/charts/map/data/oilGeo_point";
import {
  setToken
} from "../util/util";
export default {
  setToken(state, token) {
    state.token = token;
    setToken(token);
  },

  // 初始化所有状态数据
  INITALLSTATEDATA(state) {
    state.servicePersonsData = []; // 服务人次
    //state.enterPersonsData = [] // 进店人次
    //state.avgServiceTimeData = [] // 平均服务时间
    //state.managerOnlineRateData = [] // 站长在站率数据
  },
  // 获取加油区或商超区 服务人数和服务时间
  GETSERVICESTATISTIC(state, {
    getServiceData
  }) {
    //state.countData[0].value = getServiceData.servicePersonsSum
    //state.countData[2].value = getServiceData.serviceArgTime + ' 分钟'
    state.servicePersonsData = getServiceData.servicePersonsData;
    state.vehicleCongestionData = getServiceData.vehicleCongestionData;
    state.irregularParkingData = getServiceData.irregularParkingData;
    state.trafficUpFlowData = getServiceData.trafficUpFlowData;
    state.trafficDownFlowData = getServiceData.trafficDownFlowData;

    state.retrogradeData = getServiceData.retrogradeData;
    state.slowCarsData = getServiceData.slowCarsData;
    state.dangerCarsData = getServiceData.dangerCarsData;
    state.countData = getServiceData.countData;
    state.trafficFlowCount[0].value = getServiceData.countTrafficUpFlow;
    state.trafficFlowCount[1].value = getServiceData.countTrafficDownFlow;

    //state.avgServiceTimeData = getServiceData.avgServiceTimeData
  },
  // 获取报警事件查询页面的数据
  GETQUERYEVENTSTABLEDATA(state, {
    eventsTableData,
    pageData,
    constData2
  }) {
    let newEventsTableData = eventsTableData.map((ele, index) => {
      // let event_ = ele.event
      // if (ele.event === "反光衣") {
      //   event_ = "行人入侵"
      // }
      return {
        index: index +
          1 +
          (pageData.eventsPageCurrent - 1) * pageData.eventsPageSize,
        datetime: ele.starttime,
        road_name: ele.road_name,
        event: ele.event,
        //road_name: constData2.roadnameData[ele.road_name],
        //event: constData2.eventData[ele.event],
        //action: ele.action,
        //cause: ele.cause,
        //level: constData2.levelData[ele.level],
        //status: ele.status,

        //v_path: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",
        //p_path: "https://www.dummyimage.com/900x500/6495ED/fff"
        p_path: ele.p_path,
        v_path: ele.v_path,
        b_p_path: ele.b_p_path
        // http_url_image: ele.http_url_image,
        // http_url_video: ele.http_url_video,
        // video_path: ele.video_path
      };
    });
    state.eventsQueryTableData = newEventsTableData;
    //state.eventsTotal = pageData.eventsTotal
    state.eventsTotal = pageData.eventsPageSize * pageData.total_pages;
    state.eventsPageCurrent = pageData.eventsPageCurrent;
    state.eventsPageSize = pageData.eventsPageSize;
    console.log("current:" + state.eventsPageCurrent);
    console.log("pagesize:" + state.eventsPageSize);
  },
  // 更新当前页码
  UPDATEEVENTSQUERYPAGEINDEX(state, {
    currentPage
  }) {
    state.eventsPageCurrent = currentPage;
  },
  // 更新选择的站点数据
  UPDATESELECTEDSTATIONDATA(state, {
    selectedData
  }) {
    state.selectedStationData = selectedData;
  },

  //获取所有道路列表
  GETALLROADLIST(state, {
    roadList
  }) {
    let roadAll = {
      "ch_name": "全部",
      "en_name": "",
      "id": -1
    };
    roadList.push(roadAll)
    state.allRoadListData = roadList;
    console.log("state.allRoadListData:", state.allRoadListData)
  },

  //获取所有道路列表2
  GETALLROADLIST2(state, {
    roadList
  }) {
    state.allRoadListData_noneall = roadList;
    // console.log("state.allRoadListData:", state.allRoadListData)
  },

  // 获取公路视频流地址
  GETALLVIDEOSTREAMURL(state, {
    videoList,
    highWay
  }) {
    state.allVideoStreamUrl.videoDetail = videoList.video_detail;
    state.allVideoStreamUrl.videoState = videoList.video_state;
    state.switchWayNo = highWay;
    //state.monitorData.videoInfoList = videoList
    state.getStreamUrlState = 200;
  },

  // 获取公路视频流存在情况
  GETPINGRESULTS(state, {
    result
  }) {
    state.allVideoStreamPingResult = result;
  },

  // 更新对应路段视频流的监控状态信息
  GETALLVIDEOSTATE(state, {
    stateList
  }) {
    for (let index in state.allVideoStreamUrl.videoDetail) {
      road_id = state.allVideoStreamUrl.videoDetail[index].id
      state.allVideoStreamUrl.videoDetail[index].road_state = stateList[road_id.toString]
    };
    //console.log("videoState 已更新")
  },
  //更新某一道路的状态信息
  GETONEVIDEOSTATE(state, {
    stateDict
  }) {
    state.monitorData.videoSta = stateDict;
  },
  // 加载公路视频流实时播放页面
  ONLOADVIDEOSTREAMPLAYER(state, {
    steamDict,
    stateDict
  }) {
    state.monitorData.videoMsg = steamDict;
    state.monitorData.videoSta = stateDict;
    console.log("单路播放信息:", state.monitorData.videoMsg);
    console.log("单路播放状态:", state.monitorData.videoSta);
    state.monitorData.isLoadPlayer = true; // false 为不加载，true 为显示视频流播放页面
  },
  // 关闭视频流详情页，打开视频流网格页面
  CLOSEDETAILSLOADVIDEOGRIDPAGES(state) {
    state.monitorData.isLoadPlayer = false;
  },
  CHANGESWITCHWAY(state, {
    val
  }) {
    state.switchWay = val;
  },
  SETLOGOCOLOR(state, {
    val
  }) {
    state.roadLogoColor = val;
  },
  // 首页，判断地图中那些摄像头出现事件，变为红色
  SETWARNPOINT(state, {
    warnRoads
  }) {


    // for(let e in eventList){
    //   console.log("e:",e)
    //   if(eventList.indexOf(e['road_name']) === -1){
    //     warnPoint.push(e.road_name)
    //   }
    // }
    let warnPoints = []
    let normalPoints = []
    oilGeo_point.forEach(function (ele, index, array) {
      if (warnRoads.indexOf(ele.name) > -1) {
        warnPoints.push(ele)
      } else
        normalPoints.push(ele)
    });
    state.warnPoints = warnPoints
    state.normalPoints = normalPoints
    // console.log('warn',state.warnPoints)
    // console.log('nor',state.normalPoints)
  },
  REPORTALARM(state, {
    stateValue
  }) {
    console.log("报警器返回信息：", stateValue.msg)
  }
};
